{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "############## PLEASE RUN THIS CELL FIRST! ###################\n",
    "\n",
    "# import everything and define a test runner function\n",
    "from importlib import reload\n",
    "from helper import run\n",
    "import ecc\n",
    "import helper\n",
    "\n",
    "from ecc import Point"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ecc import Point\n",
    "p1 = Point(-1, -1, 5, 7)\n",
    "p2 = Point(-1, -2, 5, 7)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 1\n",
    "\n",
    "Determine which of these points are on the curve \\\\(y^{2}\\\\)=\\\\(x^{3}\\\\)+5x+7:\n",
    "\n",
    "(2,4), (-1,-1), (18,77), (5,7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Exercise 1\n",
    "\n",
    "# (2,4), (-1,-1), (18,77), (5,7)\n",
    "# equation in python is: y**2 == x**3 + 5*x + 7"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 2\n",
    "\n",
    "Write the `__ne__` method for `Point`.\n",
    "\n",
    "#### Make [this test](/edit/code-ch02/ecc.py) pass: `ecc.py:PointTest:test_ne`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Exercise 2\n",
    "\n",
    "reload(ecc)\n",
    "run(ecc.PointTest(\"test_ne\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ecc import Point\n",
    "p1 = Point(-1, -1, 5, 7)\n",
    "p2 = Point(-1, 1, 5, 7)\n",
    "inf = Point(None, None, 5, 7)\n",
    "print(p1 + inf)\n",
    "print(inf + p2)\n",
    "print(p1 + p2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 3\n",
    "\n",
    "Handle the case where the two points are additive inverses. That is, they have the same `x`, but a different `y`, causing a vertical line. This should return the point at infinity.\n",
    "\n",
    "#### Make [this test](/edit/code-ch02/ecc.py) pass: `ecc.py:PointTest:test_add0`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Exercise 3\n",
    "\n",
    "reload(ecc)\n",
    "run(ecc.PointTest(\"test_add0\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 4\n",
    "\n",
    "For the curve \\\\(y^{2}\\\\)=\\\\(x^{3}\\\\)+5x+7, what is (2,5) + (-1,-1)?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Exercise 4\n",
    "\n",
    "from ecc import Point\n",
    "\n",
    "a = 5\n",
    "b = 7\n",
    "x1, y1 = 2, 5\n",
    "x2, y2 = -1, -1\n",
    "\n",
    "# (x1,y1) + (x2,y2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 5\n",
    "\n",
    "Write the `__add__` method where \\\\(x_{1}\\\\)≠\\\\(x_{2}\\\\)\n",
    "\n",
    "#### Make [this test](/edit/code-ch02/ecc.py) pass: `ecc.py:PointTest:test_add1`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Exercise 5\n",
    "\n",
    "reload(ecc)\n",
    "run(ecc.PointTest(\"test_add1\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 6\n",
    "\n",
    "For the curve \\\\(y^{2}\\\\)=\\\\(x^{3}\\\\)+5x+7, what is (-1,-1) + (-1,-1)?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Exercise 6\n",
    "\n",
    "from ecc import Point\n",
    "\n",
    "a = 5\n",
    "b = 7\n",
    "x1, y1 = -1, -1\n",
    "# (-1,-1) + (-1,-1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 7\n",
    "\n",
    "Write the `__add__` method when \\\\(P_{1}\\\\)=\\\\(P_{2}\\\\).\n",
    "\n",
    "#### Make [this test](/edit/code-ch02/ecc.py) pass: `ecc.py:PointTest:test_add2`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Exercise 7\n",
    "\n",
    "reload(ecc)\n",
    "run(ecc.PointTest(\"test_add2\"))"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
